/**
 * 语法测试...
 */
import Vue from 'vue'
export default class Product {
  constructor (ctnID, tag) {
    this.ctnID = ctnID
    this.tag = tag || 'div'
  }
  create (vm, set) {
    let temp = new Vue({
      el: '#' + this.ctnID,
      data () {
        return {
          shit: 'sss'
        }
      },
      render: h => (
        h(this.tag, {
          attrs: {
            id: this.ctnID
          }
        }, vm.vNodes.map((ele, k) => {
          let comboxVnode = h('div', {
            class: 'combox'
          }, [
            h(ele.name, {
              attrs: {
                type: ele.type
              },
              domProps: {
                innerHTML: ele.text
              },
              on: {
                input: val => {
                  vm.vNodes[k].text = val
                  vm.$emit('input', val)
                }
              }
            }),
            // <ele.name type={ele.type} v-model={vm.vNodes[k].text}></ele.name>,
            h('span', {
              attrs: {
                class: 'del el-icon-delete'
              },
              on: {
                click (e) {
                  window.editctn.removeChild(e.target.parentNode)
                  comboxVnode.context.$destroy()
                  vm.vNodes.rm(ele)
                  console.log(vm.vNodes)
                }
              }
            })
          ])
          return comboxVnode
        }))
      )
    })
    this.productions = temp
  }
  extends (...args) {
    let i = args.length - 1
    let target = null
    let index = null
    while (i > 0) {
      index = args[i]
      target = args[i - 1]
      for (let k in index) {
        let temp = index[k]
        if (!target[k]) {
          target[k] = index[k]
        } else {
          if (typeof index[k] === 'object') {
            target[k] = this.extends(target[k], temp)
          } else {
            target[k] = index[k]
          }
        }
      }
      i--
    }
    return target
  }
}
